<% content_for :menu do %>
	<menu>
		<ul>
			<li ><%= link_to 'Accueil', :controller => :supervision %></li>
			<li id="femme_actuelle"><%= link_to 'Gestion des salles', :controller => :salles, :action => :index %></li>
			<li><%= link_to 'Gestion des machines', :controller => :machines, :action => :index %></li>
			<li><%= link_to 'Gestion des incidents', :controller => :incidents, :action => :index %></li>
			<li><%= link_to 'Gestion des logs', :controller => :logs, :action => :index %></li>
			<li ><%= link_to 'Metriques', :controller => :stats, :action => :index %></li>
		</ul>
	</menu>
<% end %>

<div class="ico_salle" id="table_salle_<%= salle.id %>">
	<table class="table_salle" >
		<tr align="center">
			
			  	<% salle_id = "salle_#{salle.id}" %>
				<td>
			  	<span class="handle_salle"><%= image_tag('dnd-move-linux.png', :alt =>"move", :height =>"32px", :width =>"32px") %></span>
				</td>
				<td>
			  	<div id="nom_<%= salle_id %>" class="nom_salle" style="cursor:move">
			  		<%= image_tag('building.png',:alt =>"Building", :height =>"16px", :width =>"16px") %><span id="nom_salle"><%=h salle.nom_salle %></span>  		
			  	</div>
			</td>
			<td>
				<%= link_to 'Voir', salle %>
	    		<%= link_to 'Modifier', edit_salle_path(salle) %>
	    		<%= link_to_remote 'Supprimer', 
	    			:url => {:controller => :salles, :action => :destroy}, 
	    			:with => "'id=#{salle.id}'", 
	    			:script => true,
	    			:before =>  "$('loading_delete_salle_salle_"+salle.id.to_s+"').show()",
	    			#:complete => "$('loading_delete_salle_"+salle_id.to_s+"').show()", 
	    			:confirm => 'Etes-vous sur de supprimer cette salle ?'%>
	    		<%= image_tag('loading.gif', :id => 'loading_delete_salle_'+salle_id.to_s, :style => "display:none", :alt =>"chargement", :height =>"16px", :width =>"16px")%>
	    	</td>
		</tr>
	</table>
	<div class="scroll">
			<table >
				<tr>
					<td colspan="2">  		
						<% @machines = Machine.find_all_by_salle_id(salle.id, :order =>"ordre") %>
						<div id="liste_machines_<%= salle.id %>">
							<%= render :partial => "machines/listMachine", :locals => { :machines => @machines, :salle_id => salle.id} %>
						</div>
					</td>
				</tr>
			</table>
		</div>
	<table>
		<tr>
			<td colspan="2">
				<div id="divLienAfficherMachine_<%= salle.id%>">
					<%= link_to_function 'Ajouter une machine', "$('divAjouterMachine_"+salle.id.to_s+"').show();$('divLienAfficherMachine_"+salle.id.to_s+"').hide()" %>
				</div>
				<div id="divAjouterMachine_<%= salle.id%>" style="display:none;">
				<% remote_form_for :machine, 
					:url => {:action => 'create', :controller => 'machines'}, 
					#:update => "liste_machines_"+salle.id.to_s ,
					:before => "$('loading_create_machine_"+salle.id.to_s+"').show()",
					:complete => "$('divAjouterMachine_"+salle.id.to_s+"').hide();$('divLienAfficherMachine_"+salle.id.to_s+"').show();$('loading_create_machine_"+salle.id.to_s+"').hide();$('new_machine_"+salle.id.to_s+"').elements['machine[nom_machine]'].value='';$('new_machine_"+salle.id.to_s+"').elements['machine[adresse_ip]'].value=''", 
					:html => { :id => "new_machine_"+salle.id.to_s, :name => "new_machine_"+salle.id.to_s  }, 
					:condition=>"validateFormMachine('"+salle.id.to_s+"')!=false" do |f| %>
					
				  <%= hidden_field_tag "machine[salle_id]", salle.id %>
				  <table>
				  	<tr>
				  		<td><%= f.label "Nom" %></td>
				  		<td><%= f.text_field :nom_machine, :size => 15 %></td>
				  		<td><span id="error_nom_machine_<%= salle.id.to_s %>" style="color:red"></span></td>
				  	</tr>
				  	<tr>
				  		<td><%= f.label "Adresse IP" %></td>
				  		<td><%= f.text_field :adresse_ip %></td>
				  		<td><span id="error_adresse_ip_<%= salle.id.to_s %>" style="color:red"></span></td>
				  	</tr>
				  	<tr>
				  		<td><%= submit_tag "Enregistrer "%></td>
				  		<td><%= image_tag('loading.gif', :id => 'loading_create_machine_'+salle.id.to_s, :style => "display:none", :alt =>"chargement", :height =>"16px", :width =>"16px")%></td>
				  	</tr>
				  </table>
				 <% end -%>
				</div>
			 </td> 
	  	</tr>
			<%= drop_receiving_element("table_salle_#{salle.id}",                             # The id of the receiving element
		  :accept => "machine",                                         # The CSS class of the dropped element
		  :with   => "'machine_id=' + (element.id.split('_').last())+'&salle_id=#{salle.id}'",     # The query string parameters
		  :url    => {:action=>:changeMachine, :controller => :machines}                          # The action to call
		)%>
		<%= draggable_element("nom_"+salle_id.to_s, :revert=>true, :ghosting => true, :change  => "function() { $('trash').show() }") %>
	  </tr>
	</table>
</div>